package com.trust.controller;


import com.trust.agri.response.ResponseResult;
import com.trust.agri.util.FtpUtil;
import com.trust.constant.InventoryTypeEnum;
import com.trust.entity.SetupBase;
import com.trust.entity.SystemCity;
import com.trust.entity.VO.*;
import com.trust.entity.result.*;
import com.trust.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/api/public")
@Api(value = "公用接口", tags = "公用接口")
public class PublicController {


    @Resource
    private FtpUtil ftpUtil;

    @Resource
    private DictionaryService dictionaryService;

    @Resource
    private SystemCityService systemCityService;

    @Resource
    private SupplyService supplyService;

    @Resource
    private MedicineService medicineService;

    @Resource
    private BreedService breedService;

    @Resource
    private MaterialInputService materialInputService;

    @Resource
    private SetupLandService setupLandService;

    @Resource
    private SystemPersonService systemPersonService;

    @Resource
    private FarmPlantService farmPlantService;

    @Resource
    private FarmSeedService farmSeedService;

    @Resource
    private InventoryMaterialService inventoryMaterialService;

    @Resource
    private FieldService fieldService;

    @Resource
    private SystemDepartmentService systemDepartmentService;

    @Resource
    private CheckoutService checkoutService;

    @Resource
    private SystemAccountRoleService systemAccountRoleService;

    @Resource
    private SetupBaseService setupBaseService;

    @Resource
    private StorehouseService storehouseService;

    @Resource
    private CustomService customService;


    @PostMapping("/upload/pic")
    @ApiOperation("批量上传图片")
    public ResponseResult<List<String>> uploadImage(@RequestPart("multipartFiles") MultipartFile[] multipartFiles){
        if (multipartFiles.length > 0){
            List<String> s = ftpUtil.uploadPictureBatch(Arrays.asList(multipartFiles));
            return ResponseResult.ok(s);
        }
        return ResponseResult.ok();
    }


    @PostMapping("/drop/down/box")
    @ApiOperation("下拉框集合")
    public ResponseResult<List<DropDownBoxResult>> dropDownBox(@RequestBody List<String> list) {
        List<DropDownBoxResult> results = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            switch (list.get(i)) {
                case "dropDown":
                    List<DropDown2Result> dropDown = new ArrayList<>();
                    dropDown.add(new DropDown2Result("baseType", "基地类型", 1));
                    dropDown.add(new DropDown2Result("otherCerBase", "其他认证基地", 6));
                    dropDown.add(new DropDown2Result("basePlantMode", "基地种植模式", 9));
                    dropDown.add(new DropDown2Result("plantStandard", "种植标准/规范", 12));
                    dropDown.add(new DropDown2Result("ecologicalMethods", "生态种植方式", 18));
                    dropDown.add(new DropDown2Result("seedSourceId", "种子/种苗来源", 27));
                    dropDown.add(new DropDown2Result("breedSite", "繁殖地点", 32));
                    dropDown.add(new DropDown2Result("breedMaterial", "繁殖材料", 35));
                    dropDown.add(new DropDown2Result("breedSource", "来源（种源）", 46));
                    dropDown.add(new DropDown2Result("holdingConditions", "贮藏条件（种源）", 51));
                    dropDown.add(new DropDown2Result("baseGroup", "地块分组", 59));
                    dropDown.add(new DropDown2Result("seedUnit", "种苗单位(药材)", 60));
                    dropDown.add(new DropDown2Result("grade", "药材等级", 62));
                    dropDown.add(new DropDown2Result("province", "省份", null));
                    dropDown.add(new DropDown2Result("materialInputType", "投入品类型", 67));
                    dropDown.add(new DropDown2Result("storageMode", "仓库储存模式", 71));
                    dropDown.add(new DropDown2Result("supply", "供应商"));
                    dropDown.add(new DropDown2Result("medicine", "物料 药材"));
                    dropDown.add(new DropDown2Result("breed", "物料 种源"));
                    dropDown.add(new DropDown2Result("materialInput", "物料 投入品"));
                    dropDown.add(new DropDown2Result("seedFacilityId", "辅助育苗设施", 74));
                    dropDown.add(new DropDown2Result("fieldActivity", "田间作业项目", 79));
                    dropDown.add(new DropDown2Result("administrativeDistrict", "省市区"));
                    dropDown.add(new DropDown2Result("baseUnit", "基础计量单位", 89));
                    dropDown.add(new DropDown2Result("land", "地块选择"));
                    dropDown.add(new DropDown2Result("plantBreedType", "育苗方式", 94));
                    dropDown.add(new DropDown2Result("person", "人员管理"));
                    dropDown.add(new DropDown2Result("farmPlant", "种植任务"));
                    dropDown.add(new DropDown2Result("farmSeed", "育苗任务"));
                    dropDown.add(new DropDown2Result("collectType", "作业方式", 115));
                    dropDown.add(new DropDown2Result("collectMethod", "作业方法", 118));
                    dropDown.add(new DropDown2Result("purchaseDetailType", "采购明细类型"));
                    dropDown.add(new DropDown2Result("stock", "库存 所有"));
                    dropDown.add(new DropDown2Result("stockMaterial", "库存 药材 原料"));
                    dropDown.add(new DropDown2Result("stockFinishMaterial", "库存 药材 成品"));
                    dropDown.add(new DropDown2Result("processModel", "加工模式"));
                    dropDown.add(new DropDown2Result("packModel", "包装模式"));
                    dropDown.add(new DropDown2Result("fieldActivityKey", "田间活动字段"));
                    dropDown.add(new DropDown2Result("storehouseBreed", "仓库可用种子"));
                    dropDown.add(new DropDown2Result("deptTree", "部门树"));
                    dropDown.add(new DropDown2Result("wayId", "整地方式"));
                    dropDown.add(new DropDown2Result("handId", "土壤处理"));
                    dropDown.add(new DropDown2Result("sowWayId", "播种方式"));
                    dropDown.add(new DropDown2Result("manureWay", "施肥方式"));
                    dropDown.add(new DropDown2Result("manureType", "肥料种类"));
                    dropDown.add(new DropDown2Result("selectWayId", "净选方式"));
                    dropDown.add(new DropDown2Result("kind", "病虫害种类"));
                    dropDown.add(new DropDown2Result("insectWayId", "防治方式"));
                    dropDown.add(new DropDown2Result("harmPart", "危害部位"));
                    dropDown.add(new DropDown2Result("degreeId", "危害程度 病虫害"));
                    dropDown.add(new DropDown2Result("drug", "农药种类"));
                    dropDown.add(new DropDown2Result("irrigateWayId", "灌溉方式"));
                    dropDown.add(new DropDown2Result("grassWayId", "除草方式"));
                    dropDown.add(new DropDown2Result("harmLevelId", "危害程度 除草"));
                    dropDown.add(new DropDown2Result("rankGrass", "杂草种类"));
                    dropDown.add(new DropDown2Result("waterId", "灌溉用水"));
                    dropDown.add(new DropDown2Result("plantCode", "可采收种植任务"));
                    dropDown.add(new DropDown2Result("seedCode", "可采收育苗任务"));
                    dropDown.add(new DropDown2Result("qualityStandards", "质检标准"));
                    dropDown.add(new DropDown2Result("qualityMode", "质检模式"));
                    dropDown.add(new DropDown2Result("role", "角色"));
                    dropDown.add(new DropDown2Result("setupBase", "基地"));
                    dropDown.add(new DropDown2Result("storehouse", "仓库"));
                    dropDown.add(new DropDown2Result("customerSupply", "客户供应品类"));
                    dropDown.add(new DropDown2Result("customer", "客户"));
                    dropDown.add(new DropDown2Result("inventoryType", "出入库类型"));
                    results.add(new DropDownBoxResult(list.get(i), dropDown));
                    break;
                case "baseType":
                    List<DictionaryVO> baseType = dictionaryService.dropDownList(1);
                    results.add(new DropDownBoxResult(list.get(i), baseType));
                    break;
                case "otherCerBase":
                    List<DictionaryVO> otherCerBase = dictionaryService.dropDownList(6);
                    results.add(new DropDownBoxResult(list.get(i), otherCerBase));
                    break;
                case "basePlantMode":
                    List<DictionaryVO> basePlantMode = dictionaryService.dropDownList(9);
                    results.add(new DropDownBoxResult(list.get(i), basePlantMode));
                    break;
                case "plantStandard":
                    List<DictionaryVO> plantStandard = dictionaryService.dropDownList(12);
                    results.add(new DropDownBoxResult(list.get(i), plantStandard));
                    break;
                case "ecologicalMethods":
                    List<DictionaryVO> ecologicalMethods = dictionaryService.dropDownList(18);
                    results.add(new DropDownBoxResult(list.get(i), ecologicalMethods));
                    break;
                case "seedSourceId":
                    List<DictionaryVO> seedSourceId = dictionaryService.dropDownList(27);
                    results.add(new DropDownBoxResult(list.get(i), seedSourceId));
                    break;
                case "breedSite":
                    List<DictionaryVO> breedSite = dictionaryService.dropDownList(32);
                    results.add(new DropDownBoxResult(list.get(i), breedSite));
                    break;
                case "breedMaterial":
                    List<DictionaryVO> breedMaterial = dictionaryService.dropDownList(35);
                    results.add(new DropDownBoxResult(list.get(i), breedMaterial));
                    break;
                case "breedSource":
                    List<DictionaryVO> breedSource = dictionaryService.dropDownList(46);
                    results.add(new DropDownBoxResult(list.get(i), breedSource));
                    break;
                case "holdingConditions":
                    List<DictionaryVO> holdingConditions = dictionaryService.dropDownList(51);
                    results.add(new DropDownBoxResult(list.get(i), holdingConditions));
                    break;
                case "baseGroup":
                    List<DictionaryVO> baseGroup = dictionaryService.dropDownList(59);
                    results.add(new DropDownBoxResult(list.get(i), baseGroup));
                    break;
                case "seedUnit":
                    List<DictionaryVO> seedUnit = dictionaryService.dropDownList(60);
                    results.add(new DropDownBoxResult(list.get(i), seedUnit));
                    break;
                case "grade":
                    List<DictionaryVO> grade = dictionaryService.dropDownList(62);
                    results.add(new DropDownBoxResult(list.get(i), grade));
                    break;
                case "province":
                    List<SystemCity> province = systemCityService.getProvince();
                    results.add(new DropDownBoxResult(list.get(i), province, false));
                    break;
                case "administrativeDistrict":
                    Object administrativeDistrict = systemCityService.getListTree();
                    results.add(new DropDownBoxResult(list.get(i), administrativeDistrict, false));
                    break;
                case "materialInputType":
                    List<DictionaryVO> materialInputType = dictionaryService.dropDownList(67);
                    results.add(new DropDownBoxResult(list.get(i), materialInputType));
                    break;
                case "storageMode":
                    List<DictionaryVO> storageMode = dictionaryService.dropDownList(71);
                    results.add(new DropDownBoxResult(list.get(i), storageMode));
                    break;
                case "supply":
                    List<DropDownResult> supply = supplyService.dropDown();
                    results.add(new DropDownBoxResult(list.get(i), supply, false));
                    break;
                case "medicine":
                    List<DropDownResult> medicine = medicineService.dropDown();
                    results.add(new DropDownBoxResult(list.get(i), medicine, false));
                    break;
                case "breed":
                    List<DropDownResult> breed = breedService.dropDown();
                    results.add(new DropDownBoxResult(list.get(i), breed, false));
                    break;
                case "materialInput":
                    List<MaterialInputDropDownResult> materialInput = materialInputService.dropDown();
                    results.add(new DropDownBoxResult(list.get(i), materialInput, false));
                    break;
                case "seedFacilityId":
                    List<DictionaryVO> seedFacilityId = dictionaryService.dropDownList(74);
                    results.add(new DropDownBoxResult(list.get(i), seedFacilityId));
                    break;
                case "fieldActivity":
                    List<DictionaryVO> fieldActivity = dictionaryService.dropDownList(79);
                    results.add(new DropDownBoxResult(list.get(i), fieldActivity));
                    break;
                case "baseUnit":
                    List<DictionaryVO> baseUnit = dictionaryService.dropDownList(89);
                    results.add(new DropDownBoxResult(list.get(i), baseUnit));
                    break;
                case "plantBreedType":
                    List<DictionaryVO> plantBreedType = dictionaryService.dropDownList(94);
                    results.add(new DropDownBoxResult(list.get(i), plantBreedType));
                    break;
                case "land":
                    LandSelectVO land = setupLandService.DropDownList();
                    results.add(new DropDownBoxResult(list.get(i), land, false));
                    break;
                case "person":
                    List<PersonDropDownResult> person = systemPersonService.dropDown(null);
                    results.add(new DropDownBoxResult(list.get(i), person, false));
                    break;
                case "farmPlant":
                    List<DropDownResult> farmPlant = farmPlantService.dropDown();
                    results.add(new DropDownBoxResult(list.get(i), farmPlant, false));
                    break;
                case "farmSeed":
                    List<DropDownResult> farmSeed = farmSeedService.dropDown();
                    results.add(new DropDownBoxResult(list.get(i), farmSeed, false));
                    break;
                case "collectType":
                    List<DictionaryVO> collectType = dictionaryService.dropDownList(115);
                    results.add(new DropDownBoxResult(list.get(i), collectType));
                    break;
                case "collectMethod":
                    List<DictionaryVO> collectMethod = dictionaryService.dropDownList(118);
                    results.add(new DropDownBoxResult(list.get(i), collectMethod));
                    break;
                case "purchaseDetailType":
                    List<DictionaryVO> purchaseDetailType = dictionaryService.dropDownList(67);
                    List<DictionaryVO> pur = new ArrayList<>();
                    pur.add(new DictionaryVO(-1, "种子"));
                    pur.add(new DictionaryVO(-2, "种苗"));
                    pur.add(new DictionaryVO(-3, "药材"));
                    pur.addAll(purchaseDetailType);
                    results.add(new DropDownBoxResult(list.get(i), pur));
                    break;
                case "stock":
                    List<InventoryMaterialDropDownVO> stock = inventoryMaterialService.dropDownList(null);
                    results.add(new DropDownBoxResult(list.get(i), stock));
                    break;
                case "stockMaterial":
                    List<InventoryMaterialDropDownVO> stockMaterial = inventoryMaterialService.dropDownList(1);
                    results.add(new DropDownBoxResult(list.get(i), stockMaterial));
                    break;
                case "stockFinishMaterial":
                    List<InventoryMaterialDropDownVO> stockFinishMaterial = inventoryMaterialService.dropDownList(2);
                    results.add(new DropDownBoxResult(list.get(i), stockFinishMaterial));
                    break;
                case "processModel":
                    List<DictionaryVO> processModel = dictionaryService.dropDownList(144);
                    results.add(new DropDownBoxResult(list.get(i), processModel));
                    break;
                case "packModel":
                    List<DictionaryVO> packModel = dictionaryService.dropDownList(148);
                    results.add(new DropDownBoxResult(list.get(i), packModel));
                    break;
                case "fieldActivityKey":
                    List<Object> fieldActivityKey = fieldService.fieldActivityKey();
                    results.add(new DropDownBoxResult(list.get(i), fieldActivityKey));
                    break;
                case "storehouseBreed":
                    List<DictionaryVO> storehouseBreed = inventoryMaterialService.storehouseBreed(-1);
                    results.add(new DropDownBoxResult(list.get(i), storehouseBreed));
                    break;
                case "deptTree":
                    List<DeptListVO> deptTree = systemDepartmentService.tree(null);
                    results.add(new DropDownBoxResult(list.get(i), deptTree));
                    break;
                case "wayId":
                    List<DictionaryVO> wayId = dictionaryService.dropDownList(154);
                    results.add(new DropDownBoxResult(list.get(i), wayId));
                    break;
                case "handId":
                    List<DictionaryVO> handId = dictionaryService.dropDownList(155);
                    results.add(new DropDownBoxResult(list.get(i), handId));
                    break;
                case "sowWayId":
                    List<DictionaryVO> sowWayId = dictionaryService.dropDownList(156);
                    results.add(new DropDownBoxResult(list.get(i), sowWayId));
                    break;
                case "manureWay":
                    List<DictionaryVO> manureWay = dictionaryService.dropDownList(157);
                    results.add(new DropDownBoxResult(list.get(i), manureWay));
                    break;
                case "manureType":
                    List<DictionaryVO> manureType = dictionaryService.dropDownList(158);
                    results.add(new DropDownBoxResult(list.get(i), manureType));
                    break;
                case "selectWayId":
                    List<DictionaryVO> selectWayId = dictionaryService.dropDownList(159);
                    results.add(new DropDownBoxResult(list.get(i), selectWayId));
                    break;
                case "kind":
                    List<DictionaryVO> kind = dictionaryService.dropDownList(160);
                    results.add(new DropDownBoxResult(list.get(i), kind));
                    break;
                case "drug":
                    List<DictionaryVO> drug = dictionaryService.dropDownList(161);
                    results.add(new DropDownBoxResult(list.get(i), drug));
                    break;
                case "insectWayId":
                    List<DictionaryVO> insectWayId = dictionaryService.dropDownList(162);
                    results.add(new DropDownBoxResult(list.get(i), insectWayId));
                    break;
                case "degreeId":
                    List<DictionaryVO> degreeId = dictionaryService.dropDownList(163);
                    results.add(new DropDownBoxResult(list.get(i), degreeId));
                    break;
                case "harmPart":
                    List<DictionaryVO> harmPart = dictionaryService.dropDownList(164);
                    results.add(new DropDownBoxResult(list.get(i), harmPart));
                    break;
                case "irrigateWayId":
                    List<DictionaryVO> irrigateWayId = dictionaryService.dropDownList(165);
                    results.add(new DropDownBoxResult(list.get(i), irrigateWayId));
                    break;
                case "rankGrass":
                    List<DictionaryVO> rankGrass = dictionaryService.dropDownList(170);
                    results.add(new DropDownBoxResult(list.get(i), rankGrass));
                    break;
                case "harmLevelId":
                    List<DictionaryVO> harmLevelId = dictionaryService.dropDownList(172);
                    results.add(new DropDownBoxResult(list.get(i), harmLevelId));
                    break;
                case "grassWayId":
                    List<DictionaryVO> grassWayId = dictionaryService.dropDownList(173);
                    results.add(new DropDownBoxResult(list.get(i), grassWayId));
                    break;
                case "waterId":
                    List<DictionaryVO> waterId = dictionaryService.dropDownList(175);
                    results.add(new DropDownBoxResult(list.get(i), waterId));
                    break;
                case "plantCode":
                    List<PlantDropDown> plantCode = farmPlantService.dropDownList();
                    results.add(new DropDownBoxResult(list.get(i), plantCode));
                    break;
                case "seedCode":
                    List<PlantDropDown> seedCode = farmSeedService.dropDownList();
                    results.add(new DropDownBoxResult(list.get(i), seedCode));
                    break;
                case "qualityStandards":
                    List<CheckoutDropDown> qualityStandards = checkoutService.dropDown();
                    results.add(new DropDownBoxResult(list.get(i), qualityStandards));
                    break;
                case "qualityMode":
                    List<DictionaryVO> qualityMode = dictionaryService.dropDownList(177);
                    results.add(new DropDownBoxResult(list.get(i), qualityMode));
                    break;
                case "role":
                    List<DictionaryVO> role = systemAccountRoleService.dropDownList();
                    results.add(new DropDownBoxResult(list.get(i), role));
                    break;
                case "setupBase":
                    List<SetupBase> setupBase = setupBaseService.dropDownList();
                    results.add(new DropDownBoxResult(list.get(i), setupBase));
                    break;
                case "storehouse":
                    List<DropDownResult> storehouse = storehouseService.dropDownList();
                    results.add(new DropDownBoxResult(list.get(i), storehouse));
                    break;
                case "customerSupply":
                    List<DictionaryVO> customerSupply = dictionaryService.dropDownList(241);
                    results.add(new DropDownBoxResult(list.get(i), customerSupply));
                    break;
                case "customer":
                    List<DropDownResult> customer = customService.dropDownList();
                    results.add(new DropDownBoxResult(list.get(i), customer));
                    break;
                case "inventoryType":
                    List<DictionaryVO> inventoryType = new ArrayList<>();
                    inventoryType.add(new DictionaryVO(InventoryTypeEnum.PURCHASE_IN.getId(), InventoryTypeEnum.PURCHASE_IN.getName()));
                    inventoryType.add(new DictionaryVO(InventoryTypeEnum.PROCESS_OUT.getId(), InventoryTypeEnum.PROCESS_OUT.getName()));
                    inventoryType.add(new DictionaryVO(InventoryTypeEnum.PROCESS_IN.getId(), InventoryTypeEnum.PROCESS_IN.getName()));
                    inventoryType.add(new DictionaryVO(InventoryTypeEnum.SEED_OUT.getId(), InventoryTypeEnum.SEED_OUT.getName()));
                    inventoryType.add(new DictionaryVO(InventoryTypeEnum.PLANT_OUT.getId(), InventoryTypeEnum.PLANT_OUT.getName()));
                    inventoryType.add(new DictionaryVO(InventoryTypeEnum.SALE_OUT.getId(), InventoryTypeEnum.SALE_OUT.getName()));
                    inventoryType.add(new DictionaryVO(InventoryTypeEnum.COLLECT_IN.getId(), InventoryTypeEnum.COLLECT_IN.getName()));
                    results.add(new DropDownBoxResult(list.get(i), inventoryType));
                    break;
                default:
                    break;
            }
        }
        return ResponseResult.ok(results);
    }
}
